package cn.chencaiju.day10;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import org.junit.Test;

public class FileCopy {
	public static final File source=new File("E:\\camp\\教学视频\\day09\\02.mp4");
	public static final File target=new File("test.mp4");
	
	/**
	 * 文件复制
	 * @param source 源文件
	 * @param target 目标文件
	 */
	public static void CopyFile(File source,File target) {
		try (	FileInputStream fi=new FileInputStream(source);
				FileOutputStream fo=new FileOutputStream(target);
			){
			int count=0;
			byte[] contents = new byte[1024];
			while ((count= fi.read(contents))!=-1) {
				fo.write(contents,0, count);
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e1) {
			e1.printStackTrace();
		}
	}
	@Test public void testCopy() {
		CopyFile(source,target);
	}
}
